import abc
from enum import Enum


class ClawType(Enum):
    """夹爪类型枚举"""
    ROBOTCLAW_2_5 = "RobotClaw_2_5"
    ROBOTCLAW_3_0 = "RobotClaw_3_0"
    CUSTOM_CLAW = "Custom_Claw"


class CanBitRate(Enum):
    """CAN波特率枚举"""
    RATE_125K = 125000
    RATE_250K = 250000
    RATE_500K = 500000
    RATE_1M = 1000000


class RobotClaw(abc.ABC):
    """机器人夹爪基类，提供夹爪控制的基本接口"""
    
    def __init__(self, claw_type: ClawType, can_bitrate: CanBitRate = CanBitRate.RATE_500K):
        """
        初始化夹爪
        
        Args:
            claw_type: 夹爪类型
            can_bitrate: CAN通信波特率，默认为500K
        """
        self.claw_type = claw_type
        self.can_bitrate = can_bitrate
        self._initialize_can()
        self._initialize_claw()
    
    def _initialize_can(self):
        """初始化CAN通信"""
        # 在子类中实现具体的CAN初始化逻辑
        print(f"初始化CAN通信，波特率: {self.can_bitrate.value}")
    
    def _initialize_claw(self):
        """初始化夹爪"""
        # 在子类中实现具体的夹爪初始化逻辑
        print(f"初始化夹爪，类型: {self.claw_type.value}")
    
    @abc.abstractmethod
    def open_claw(self, position: float = None, speed: float = None):
        """
        打开夹爪
        
        Args:
            position: 目标位置，可选参数
            speed: 运动速度，可选参数
        """
        pass
    
    @abc.abstractmethod
    def close_claw(self, position: float = None, speed: float = None):
        """
        关闭夹爪
        
        Args:
            position: 目标位置，可选参数
            speed: 运动速度，可选参数
        """
        pass
    
    @abc.abstractmethod
    def get_pos(self) -> float:
        """
        获取夹爪当前位置
        
        Returns:
            夹爪当前位置值
        """
        pass
    
    def get_claw_type(self) -> ClawType:
        """获取夹爪类型"""
        return self.claw_type
    
    def get_can_bitrate(self) -> CanBitRate:
        """获取CAN波特率"""
        return self.can_bitrate